package com.example.interceptor.demos.controller;

import com.example.interceptor.demos.common.ResultAjax;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2023-12-04
 * Time:20:22
 * Text：异常统一、返回数据统一、拦截器
 */
@RestController
@RequestMapping("/user")
public class UserController {
//    统一返回格式
    @RequestMapping("/getuser")
    public ResultAjax getUser(){
        System.out.println("do getUser()");
        return  ResultAjax.succ("user");
    }
//    输出空指针异常信息
    @RequestMapping("/reg")
    public String reg(){
        Object obj=null;
        System.out.println(obj.hashCode());
        return "reg";
    }
//如果外来者不使用ResultAjax，则可设置 ResponseAdvice    返回统一格式
    @RequestMapping("/login")
    public int login(){
        System.out.println("do login()");
        return 1;
    }
//例外示例
    @RequestMapping("/St")
    public String st(){
        return "123";
    }


}
